<?php
class Media extends AppModel{
    public $useTable  = 'media';
    public $lang_code = 'vn';
    
    public function get_media_by_category_id($category_id = null)
    {
        if($category_id == null)
            return array();
        
        $lang_code = $this->lang_code;
        $sql =  "SELECT media.*, media_desc.*, image.`name` 
                FROM media_desc, media
                LEFT JOIN image ON media.media_id = image.post_id 
                WHERE media.media_id = media_desc.media_id AND category_id = '$category_id' AND media.`status` = 1 AND media_desc.lang_code = '$lang_code'
                ORDER BY media.sort_order ASC, media.media_id DESC";
        $media = $this->query($sql);
        return $media;
    }
}